use "C:\Users\max.margulies\OneDrive - West Point\Desktop\Research\Patrons and Personnel\Patrons and Personnel_SS Submission\Acceptance Files\Patrons and Personnel December 2020 dataset.dta", clear

graph set window fontface "Garamond"

***Generate Figure 1: "Fig. 1: Frequency of IMD with Different Patron and Colonizer"

graph drop _all

gen diff_patron_colonizer=0 if nopatron==0
replace diff_patron_colonizer=1 if nopatron==0 & patron_id!=colruler

gen UKcolonizer_notpatron=0 if colruler==200 & patron_id==200
replace UKcolonizer_notpatron=1 if colruler==200 & patron_id!=200 & nopatron==0

gen Francecolonizer_notpatron=0 if colruler==220 & patron_id==220
replace Francecolonizer_notpatron=1 if colruler==220 & patron_id!=220 & nopatron==0

gen Russiacolonizer_notpatron=0 if colruler==365 & patron_id==365
replace Russiacolonizer_notpatron=1 if colruler==365 & patron_id!=365 & nopatron==0

gen Spaincolonizer_notpatron=0 if colruler==230 & patron_id==230
replace Spaincolonizer_notpatron=1 if colruler==230 & patron_id!=230 & nopatron==0

gen Turkeycolonizer_notpatron=0 if colruler==640 & patron_id==640
replace Turkeycolonizer_notpatron=1 if colruler==640 & patron_id!=640 & nopatron==0

twoway hist UKcolonizer_notpatron, freq discrete graphregion(color(white)) bcolor(black) plotregion(margin(b=0)) gap(5) xlabel(0 "Same Patron" 1 "Different Patron") xtitle("UK Colonizer") name(ukgraph)
twoway hist Francecolonizer_notpatron, freq discrete graphregion(color(white)) bcolor(black) plotregion(margin(b=0)) gap(5) xlabel(0 "Same Patron" 1 "Different Patron") xtitle("France Colonizer") name(francegraph) 
twoway hist Russiacolonizer_notpatron, freq discrete graphregion(color(white)) bcolor(black) plotregion(margin(b=0)) gap(5) xlabel(0 "Same Patron" 1 "Different Patron") xtitle("Russia Colonizer") name(russiagraph)
twoway hist Turkeycolonizer_notpatron, freq discrete graphregion(color(white)) bcolor(black) plotregion(margin(b=0)) gap(5) start(0) xlabel(0 "Same Patron" 1 "Different Patron") xtitle("Turkey Colonizer") name(turkeygraph)

graph combine ukgraph francegraph russiagraph turkeygraph, ycommon graphregion(color(white))

graph export figure1.tif, replace

***Generate Figure 2: "Fig. 2: The Effect of American Patronage Before and After the All-Volunteer Force"

graph drop _all

twoway hist dvdummy if patron_id==2 & (year<1973 & year>=1945), freq discrete graphregion(color(white)) bcolor(black) plotregion(margin(b=0)) gap(5) xlabel(0 "Volunteer Client" 1 "Conscript Client") xtitle("Pre-All Volunteer Force") name(USpre73)

twoway hist dvdummy if patron_id==2 & year>=1973, freq discrete graphregion(color(white)) bcolor(black) plotregion(margin(b=0)) gap(5) xlabel(0 "Volunteer Client" 1 "Conscript Client") xtitle("Post-All Volunteer Force") name(USpost73)

graph combine USpre73 USpost73, ycommon graphregion(color(white))

graph export figure2.tif, replace

***Statistical analysis:

*control variables for colonial recruitment legacy
gen colruler_volunteer = .
replace colruler_volunteer=0 if colruler!=. 
replace colruler_volunteer=1 if colruler==200 
replace colruler_volunteer=1 if colruler==2
replace colruler_volunteer=1 if colruler==900
replace colruler_volunteer=1 if colruler==920

gen colruler_volunteer2 = colruler_volunteer
replace colruler_volunteer2=. if colruler==-9

*create british vs no colonial legacy vs other colonial legacy
gen colruler_tri=.
replace colruler_tri=1 if colruler==200
replace colruler_tri=-1 if (colruler!=200 & colruler!=. & colruler!=-9)
replace colruler_tri=0 if colruler==-9

recode patron_id (2/900=1), gen(anypatron)

*Table 1:

logit dvdummy tri_patron rulerbrit midshostafter1, robust cluster(ccode)
logit dvdummy tri_patron rulerbrit midshostafter1 urbanpop democ7 noborders, robust cluster(ccode)
logit dvdummy con vol rulerbrit midshostafter1 urbanpop democ7 noborders, robust cluster(ccode)
logit dvdummy con vol colruler_volunteer midshostafter1 urbanpop democ7 noborders, robust cluster(ccode)

*Generating Fig 3: "Predicted Probabilities of Conscription"

qui logit dvdummy con vol rulerbrit midshostafter1 urbanpop democ7 noborders, robust cluster(ccode)
margins, at(conscriptpatron=0 volunteerpatron=1 rulerbrit midshostafter1 urbanpop democ7 noborders=0) saving(file1, replace)
margins, at(conscriptpatron=0 volunteerpatron=0 rulerbrit midshostafter1 urbanpop democ7 noborders=0) saving(file2, replace)
margins, at(conscriptpatron=1 volunteerpatron=0 rulerbrit midshostafter1 urbanpop democ7 noborders=0) saving(file3, replace)
combomarginsplot file1 file2 file3, plotopts(connect(i)) xlabel(.5 " " 1 "Volunteer Patron" 2 "No Patron" 3 "Conscript Patron" 3.5 " ", notick) xtitle("") ytitle("Probability of Conscription") ylabel(0(.2)1) graphregion(color(white)) file1opts(color(black)) fileci1opts(color(black)) 

*Generating Fig. 4:  "Observed Values vs. Predicted Probability of Conscription"

qui logit dvdummy tri rulerbrit midshostafter1 urbanpop democ7 noborders, robust cluster(ccode)

predict p_tri
recode p_tri (0/.199999=0) (.2/.399999=1) (.4/.599999=2) (.6/.799999=3) (.8/1=4), gen(ptri_cat)

gen dvdummyflip=(dvdummy*-1)+1
recode dvdummy (0=.), gen(dvconscript)
recode dvdummyflip (0=.), gen(dvvolunteer)

graph bar (count) dvconscript dvvolunteer if conscriptpatron==1, over(ptri_cat, relabel(1 "0-19%" 2 "20-39%" 3 "40-59%" 4 "60-79%" 5 "80-100%")) ///
	legend(label(1 "Observed" "Conscript") label(2 "Observed" "Volunteer")) ///
	title("IMD with Conscript Patrons") ///
	caption("Predicted Probabilities") ///
	ytitle("Number of Observations") ///
	blabel(total) ///
	stack ///
	graphregion(color(white)) ///
	name(con1, replace)
graph bar (count) dvconscript dvvolunteer if volunteerpatron==1, over(ptri_cat, relabel(1 "0-19%" 2 "20-39%" 3 "40-59%" 4 "60-79%" 5 "80-100%")) allcategories ///
	legend(label(1 "Observed" "Conscript") label(2 "Observed" "Volunteer")) ///
	title("IMD with Volunteer Patrons") ///
	caption("Predicted Probabilities") ///
	ytitle("Number of Observations") ///
	blabel(total) ///
	stack ///
	graphregion(color(white)) ///
	name(vol1, replace)
	
graph combine con1 vol1, graphregion(color(white))

***Appendix:

*Table A1:
tab dvdummy if vol==1
tab dvdummy if nopatron==1
tab dvdummy if con==1

tab dvdummy if vol==1 & icow==1
tab dvdummy if nopatron==1 & icow==1
tab dvdummy if con==1 & icow==1

tab dvdummy if vol==1 & (icow==1 & system==1)
tab dvdummy if nopatron==1 & (icow==1 & system==1)
tab dvdummy if con==1 & (icow==1 & system==1)

tab dvdummy if vol==1 & (icow==1 | system==1)
tab dvdummy if nopatron==1 & (icow==1 | system==1)
tab dvdummy if con==1 & (icow==1 | system==1)

tab dvdummy if vol==1 & (icow==0 & system==0)
tab dvdummy if nopatron==1 & (icow==0 & system==0)
tab dvdummy if con==1 & (icow==0 & system==0)

*Table A2:

gen newentry=0
replace newentry=1 if icow==1 | system==1

logit dvdummy con vol rulerbrit midshostafter1 urbanpop democ7 noborders newentry, robust cluster(ccode)
logit dvdummy con vol rulerbrit midshostafter1 urbanpop democ7 noborders rev, robust cluster(ccode)
logit dvdummy con vol rulerbrit midshostafter1 urbanpop democ7 noborders cowcivilwar, robust cluster(ccode)
logit dvdummy tri rulerbrit midshostafter1 urbanpop democ7 noborders if newentry==1, robust cluster(ccode)
logit dvdummy tri rulerbrit midshostafter1 urbanpop democ7 noborders if newentry==0, robust cluster(ccode)

*Table A3:

logit dvdummy10 tri rulerbrit midshostafter1 urbanpop democ7 noborders, robust cluster(ccode)
logit dvdummy10 tri rulerbrit midshostafter1 urbanpop democ7 noborders if icow==1, robust cluster(ccode)
logit dvdummy20 tri rulerbrit midshostafter1 urbanpop democ7 noborders, robust cluster(ccode)
logit dvdummy20 tri rulerbrit midshostafter1 urbanpop democ7 noborders if icow==1, robust cluster(ccode)
reg mean_conscript tri rulerbrit midshostafter1 urbanpop democ7 noborders if icow==1, robust cluster(ccode)

*Table A4:

count if foreigntrainers==1 & secondeddummy==0 & troopsdummy==0
count if foreigntrainers==0 & secondeddummy==1 & troopsdummy==0
count if foreigntrainers==0 & secondeddummy==0 & troopsdummy==1
count if foreigntrainers==1 & secondeddummy==1 & troopsdummy==0
count if foreigntrainers==1 & secondeddummy==0 & troopsdummy==1
count if foreigntrainers==0 & secondeddummy==1 & troopsdummy==1
count if foreigntrainers==1 & secondeddummy==1 & troopsdummy==1
count if foreigntrainers==1 | secondeddummy==1 | troopsdummy==1

*Table A5:

logit dvdummy con midshostafter1 urbanpop democ7 noborders if rulerbrit==1, robust cluster(ccode)
logit dvdummy vol midshostafter1 urbanpop democ7 noborders if rulerbrit==1, robust cluster(ccode)
logit dvdummy con midshostafter1 urbanpop democ7 noborders if rulerbrit==0, robust cluster(ccode)
logit dvdummy vol midshostafter1 urbanpop democ7 noborders if rulerbrit==0, robust cluster(ccode)

recode colruler (-9=0), gen(colruler2) 
logit dvdummy con rulerbrit midshostafter1 urbanpop democ7 noborders if patron_id!=colruler2, robust cluster(ccode)
logit dvdummy vol rulerbrit midshostafter1 urbanpop democ7 noborders if patron_id!=colruler2, robust cluster(ccode)